Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

133
Vistas
devolver variables de la función de flecha [JS]

Tengo esta función getData que leerá una lista de ID de un archivo JSON. la lista de ID se almacena en la variable idsList que necesito usar dentro de otra función. ¿Cómo devuelvo el valor de esta función?

 function getData(){ fetch("JSONitemIDsList.json") .then(response => response.json()) .then(data => { let idsList = data.ids //return idsList }) } function myFunc(idsList) { //do something with idsList }
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Puedes abordar esto de muchas maneras. Por ejemplo:

 // with async / await async function getData() { try { const rawData = await fetch("JSONitemIDsList.json") const data = await rawData.json() return data } catch (err) { // handle error here console.log(err) } } async function myFunc() { const idsList = await getData() //do something with idsList }

o

 // define first function myFunc(idsList) { //do something with idsList } function getData(){ fetch("JSONitemIDsList.json") .then(response => response.json()) .then(data => { // function call myFunc(data.ids) }) }
about 4 years ago · Juan Pablo Isaza Denunciar

0

Puedes probar esto:

 const reqResponse = fetch("JSONitemIDsList.json") .then(response => response.json()) // I am not sure, if your data is already in the format that you need, otherwise, you can run one more .then() to format it } const getIdList= async () => { const idList = await reqResponse; console.log(idList) // use idList to access the information you need }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda